package suzf.top.kotlinjava.common.config

import org.springframework.context.annotation.Configuration
import org.springframework.http.converter.HttpMessageConverter
import org.springframework.http.converter.StringHttpMessageConverter
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport
import java.nio.charset.StandardCharsets

/**
 *
 *========================
 * Created with IntelliJ IDEA
 * Author:Mr.Su
 * Date:2019/9/23
 * Time:13:46
 * ========================
 */
@Configuration
class MyConfiguration: WebMvcConfigurationSupport() {

    override fun extendMessageConverters(converters: MutableList<HttpMessageConverter<*>>) {
        super.extendMessageConverters(converters)
        // 解决controller返回字符串中文乱码问题
        for (converter in converters) {
            if (converter is StringHttpMessageConverter) {
                converter.defaultCharset = StandardCharsets.UTF_8
            }
        }
    }
}
